home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++,comp.os.ms-windows.programmer.misc
- Path: netcom.com!marnold
- From: marnold@netcom.com (Matt Arnold)
- Subject: Re: Compiler Bug - can call private constructors.
- Message-ID: <marnoldDMyJKr.JoG@netcom.com>
- Organization: NETCOM On-line Communication Services (408 261-4700 guest)
- References: <311a149f.8353477@hector> <4fookc$m05@Milpitas01.Pop.Internex.NET>
- Date: Sun, 18 Feb 1996 06:05:15 GMT
- Sender: marnold@netcom5.netcom.com
-
- Artyom@kansmen.com (Art Shelest) writes:
-
- >In article <311a149f.8353477@hector>, Kenn@owl-uk.co.uk (Ken Nicolson) wrote:
- >>Hi everyone,
- >>
- >>Running Visual C++ v4.0, I want declare the default constructor as being
- >>private, to ensure that the developer initialises the class with a string,
- >>say, or when I am implementing a Singleton, to ensure that noone else can
- >>create another instance of the class. However, I find that I can return (or
- >>throw) an object created by the default private constructor, without any
- >>warning from the compiler, from anywhere outside the class!
- >>
- >>>>>> SAMPLE CODE REPRODUCING PROBLEM
- >>
- >>#include <stdio.h>
- >>#include <iostream.h>
- >>
- >>class FOOBAR
- >>{
- >>private:
- >> FOOBAR()
- >> {
- >> cout << "I've called a private constructor!\n";
- >> }
- >>};
- >>
- >>
- >>FOOBAR foobar()
- >>{
- >>// FOOBAR b; SYNTAX ERROR, as expected
- >> return FOOBAR( ); // This is wrong
- >>}
-
- >Ah, so I'm not going crazy:
-
- >array declaration "works" too:
-
- > FOOBAR ms_sucks[2]; // should not compile, but does.
-
-
- Man, this is the *latest* edition of Visual C++? Who is MS kidding?
- Perhaps you should consider a competive upgrade to Borland C++ 5.0
- when it comes out next month.
-
-
- Sure glad he's using a compiler that gets the *basics* right,
- Matt
-